//
//  OANewEmailController.m
//  OASystem
//
//  Created by zhoupengfei on 15/4/15.
//  Copyright (c) 2015年 zpf. All rights reserved.
//
#import "gerenemailViewController.h"
#import <QuickLook/QuickLook.h>
#import "OANewEmailController.h"
#import "Toast+UIView.h"
#import "HttpTools.h"
#import "MBProgressHUD.h"
#import "GDataDefines.h"
#import "OASubNameListModel.h"
#import "OAAttachmentsModel.h"
#import "OACityNameViewController.h"
#import "OAMainAddressViewController.h"

@interface OANewEmailController ()<UITextFieldDelegate,UITextViewDelegate,QLPreviewControllerDataSource,QLPreviewControllerDelegate>

@end

@implementation OANewEmailController

- (void)viewDidLoad {
    [super viewDidLoad];
  
    if([_newtype isEqualToString:@"ks"]||[_newtype isEqualToString:@"kszf"]||[_newtype isEqualToString:@"kscg"]){
 _url = KexchksmailURL;
    _method = KSendMailMethod;
    }else{
    
    _url = KexchmailURL;
    _method = KSendMailMethod;
    }
    
        self.automaticallyAdjustsScrollViewInsets = NO;
self.edgesForExtendedLayout = UIRectEdgeNone;
    [self setupTextFieldRightView];
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(keybordDown1)];
//    [self.view addGestureRecognizer:tap];
   
self.tableView.bounces = NO;
    [self setValueToView];
               [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNo:) name:@"2222" object:nil];

}
- (void)receiveNo:(NSNotification *)no{

     NSMutableArray *array = no.userInfo[@"text"];
    
     NSString *str = nil;

  for (NSString *str1 in array) {
    if (str.length == 0) {
   str  = [NSString stringWithFormat:@"%@",str1];

}else {
   str = [NSString stringWithFormat:@"%@,%@",str1,str];

}
    
    
    
  }
      if(self.sendTextField.text.length>0){
          self.sendTextField.text = [NSString stringWithFormat:@"%@,%@",self.sendTextField.text,str ];

}else{
  self.sendTextField.text = str;
}
}
-(void)getSelectName:(NSNotification*)note{
    
    NSArray * array = note.userInfo[@"SelectName"];
    if(self.sendTextField.text.length>0){
    self.sendTextField.text = [NSString stringWithFormat:@"%@,%@",self.sendTextField.text,[array componentsJoinedByString:@","] ];
    }else{
     self.sendTextField.text =[array componentsJoinedByString:@","];
    
    }
    
}

- (void)keybordDown1 {
    [self.view endEditing:YES];
    }
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]) {
//        [textView resignFirstResponder];
//        return NO;
        return YES;

    }
    
    return YES;
    
}
#pragma mark 设置右边的view
-(void)setupTextFieldRightView{
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(keybordDown)];
//    [self.view addGestureRecognizer:tap];
    
//    UIView * rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
//    rightView.backgroundColor = [UIColor clearColor];
//    UIButton * addNameBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [addNameBtn setImage:[UIImage imageNamed:@"addName.png"] forState:UIControlStateNormal];
//    addNameBtn.frame = CGRectMake(0, 0, 40, 40);
//    [addNameBtn addTarget:self action:@selector(addNameAction:) forControlEvents:UIControlEventTouchUpInside];
//    [rightView addSubview:addNameBtn];
    
//    self.sendTextField.rightView = rightView;
//    self.sendTextField.rightViewMode=UITextFieldViewModeAlways;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getSelectName:) name:@"PostSelectNameNoti" object:nil];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

if(self.type == Reply){
    return 1;

}else
{
    return 2;
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return 3;
            break;
        case 1:
            return self.attachmentArray.count;
                default:
            return 1;
            break;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   if (indexPath.section == 0) {
if (indexPath.row==0) {
static NSString *cellid0 = @"cell0";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid0];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid0];
 UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 80, cell.contentView.height)];
    label.text = @"收件人 :";
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _sendTextField = [[UITextField alloc]init];
           _sendTextField.layer.borderColor = [[UIColor blackColor] CGColor];
      _sendTextField.frame = CGRectMake(label.right, label.top+5, KScreenWidth-100, cell.height-10);
            _sendTextField.layer.borderColor = UIColor.blackColor.CGColor;
            _sendTextField.layer.borderWidth = 1;

//      UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.2];
//      _sendTextField.backgroundColor = myColor;
 [_sendTextField setFont:[UIFont systemFontOfSize:12]];
      _sendTextField.delegate = self;
//       UIView * rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
//    rightView.backgroundColor = [UIColor clearColor];
    UIButton * addNameBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [addNameBtn setImage:[UIImage imageNamed:@"addName.png"] forState:UIControlStateNormal];
    addNameBtn.frame = CGRectMake(0, 0, 40, 40);
    [addNameBtn addTarget:self action:@selector(addNameAction:) forControlEvents:UIControlEventTouchUpInside];
//    [_sendTextField addSubview:addNameBtn];
    
    self.sendTextField.rightView = addNameBtn;
    self.sendTextField.rightViewMode=UITextFieldViewModeAlways;
       [cell.contentView addSubview:_sendTextField];
       }
if ([_types isEqualToString:@"grcg"]||[_types isEqualToString:@"kscg"]) {//编辑{
   
       self.sendTextField.text = self.SenddetailModel.sourceFrom;

   }else if (self.type == Reply){
          self.sendTextField.text = self.SenddetailModel.sendTo;

   
   }
             return cell;

}
else if(indexPath.row == 1){
 static NSString *cellid1 = @"cell1";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid1];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid1];
       
 UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 80, cell.contentView.height)];
    label.text = @"主题 :";
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
      _subjectTextField = [[UITextView alloc]init];
 
           _subjectTextField.layer.borderColor = [[UIColor blackColor] CGColor];
  CGFloat  titleFloat  = [OAToolBox sizebyText:self.SenddetailModel.title font:12 minsWidth:100];
if(titleFloat>34){
      _subjectTextField.frame = CGRectMake(label.right, label.top+5, KScreenWidth-100, titleFloat);


}else{
      _subjectTextField.frame = CGRectMake(label.right, label.top+5, KScreenWidth-100, 34);

}
       _subjectTextField.layer.borderColor = UIColor.blackColor.CGColor;
            _subjectTextField.layer.borderWidth = 1;

//      UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.2];
//      _sendTextField.backgroundColor = myColor;
 [_subjectTextField setFont:[UIFont systemFontOfSize:12]];
      _subjectTextField.delegate = self;
                 self.subjectTextField.text = self.SenddetailModel.title;

       [cell.contentView addSubview:_subjectTextField];
        
        }

                 return cell;

    
    
        }
        else{
        
        
        
static NSString *cellid2 = @"cell2";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellid2];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid2];
   UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 80, 20)];
    label.text = @"内容 :";
    label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
              CGFloat  titleFloat  = [OAToolBox sizebyText:_context font:12 minsWidth:40];

      _contentText = [[UITextView alloc]init];
           _contentText.layer.borderColor = [[UIColor blackColor] CGColor];
           if (titleFloat<170){
                 _contentText.frame = CGRectMake(10, label.bottom+10, KScreenWidth-20, 170);

           
           }
           else{
//      _contentText.frame = CGRectMake(10, label.bottom+10, KScreenWidth-20, 170);

      _contentText.frame = CGRectMake(10, label.bottom+10, KScreenWidth-20, titleFloat);
}
      UIColor *myColor = [UIColor colorWithWhite:0.5 alpha:0.2];
      _contentText.backgroundColor = myColor;
 [_contentText setFont:[UIFont systemFontOfSize:12]];
      _contentText.delegate = self;
       [cell.contentView addSubview:_contentText];
       }
       _contentText.text = _context;
             return cell;





}
}else if (indexPath.section == 1){
            static NSString * cellIdentifier = @"cellId";
            UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
            }
            OAAttachmentsModel * model = self.attachmentArray[indexPath.row];
            cell.textLabel.text = model.attachmentsTitle;
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            cell.textLabel.numberOfLines = 0;
            cell.textLabel.textColor = [UIColor colorWithRed:85/255.0 green:85/255.0  blue:85/255.0 alpha:1.0];
            return cell;

        }
        else{
        
        return nil;
        }


}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
if (indexPath.row == 2) {
              CGFloat  titleFloat  = [OAToolBox sizebyText:_context font:12 minsWidth:40];

 if (titleFloat<170){
             return 200;

           
           }
           else{
return titleFloat+30;
}




    return 200;
}else if (indexPath.row==1){
   CGFloat  titleFloat  = [OAToolBox sizebyText:self.SenddetailModel.title font:12 minsWidth:100];
if(titleFloat>34){
return titleFloat+10;


}else{
return 44;

}

}


else{
return 44;


}
}else{

return 44;

}

}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section==1) {
        UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 21)];
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, KScreenWidth, 21)];
        label.text = @"附件(iphone操作系统不支持附件上传)";
       // label.backgroundColor = [UIColor grayColor];
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = [UIColor colorWithRed:85/255.0 green:85/255.0  blue:85/255.0 alpha:1.0];
        [bgView addSubview:label];
//        if (self.attachmentArray.count) {
//            label.hidden = NO;
//        }else{
//            label.hidden = YES;
//        }
        return bgView;
    }
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==1) {
        return 21;
    }
    return 0.001;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    if (indexPath.section == 1) { //下载附件 查看附件信息
//        OAAttachmentsModel * model = self.mainattachmentArray[indexPath.row];
//        [self openFileURL:model.attachmentsURL];
//    }

     if (indexPath.section == 1){
        OAAttachmentsModel * model = self.attachmentArray[indexPath.row];
//        [self openFileURL:model.attachmentsURL];
 fujianwebViewController *vc = [[fujianwebViewController alloc]init];
        vc.url = model.attachmentsURL;
        [self.navigationController pushViewController:vc animated:YES];
    }else{
    
        [self.view endEditing:YES];

}
    
}
-(void)openFileURL:(NSString*)url{
    NSString * stringurl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    self.attacmentURL =  [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[url lastPathComponent]]; //附件路径
 
    if ([self isExtistFilePathWithFileName:[[NSURL URLWithString:stringurl] lastPathComponent]]) { //已经存在附件
        QLPreviewController *previewoCntroller = [[QLPreviewController alloc] init] ;
        previewoCntroller.delegate=self;
        previewoCntroller.dataSource=self;
        previewoCntroller.navigationItem.rightBarButtonItem=nil;
        [self.navigationController pushViewController: previewoCntroller animated:YES];
        
    }else{
        MBProgressHUD * hud  =  [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.labelText = @"下载中...";
        NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:stringurl]];
        [self.webView loadRequest:request];
    }
    
}

#pragma mark PreviewDataSource
//第一个方法是设定一组文档浏览的个数，会影响到在文档预览中的上/下一页。
-(NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
    return 1;
}
//第二个方法是指定文档预览的文件路径
-(id<QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
    
    return [NSURL fileURLWithPath:self.attacmentURL];
}

-(BOOL)isExtistFilePathWithFileName:(NSString*)fileName{
    NSString * file = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString * filePath = [file stringByAppendingPathComponent:fileName];
    NSFileManager * fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:filePath] && fileName.length != 0) {
        return YES;
    }else{
        return NO;
    }
    
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    NSURL * requestedURL = [request URL];
    NSData * fileData = [[NSData alloc] initWithContentsOfURL:requestedURL];
    NSString * filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
     [fileData writeToFile:[filePath stringByAppendingPathComponent:[requestedURL lastPathComponent]] atomically:YES];
      return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
    
    
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
    QLPreviewController *previewoCntroller = [[QLPreviewController alloc] init] ;
    previewoCntroller.delegate=self;
    previewoCntroller.dataSource=self;
    [self.navigationController pushViewController: previewoCntroller animated:YES];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}
// 桐乡app测试bug总汇:


-(void)setValueToView{
    if (self.type == Reply) {//回复
         self.title = @"回复";
        self.sendTextField.rightView = [[UIView alloc] init];
//        self.sendTextField.text = self.detailModel.sender;
        self.subjectTextField.text = [NSString stringWithFormat:@"回复 :%@",_SenddetailModel.title];
               self.SenddetailModel.title =[NSString stringWithFormat:@"回复 :%@",self.SenddetailModel.title];

    }else if ([_types isEqualToString:@"grcg"]||[_types isEqualToString:@"kscg"]) //编辑
    {
 self.sendTextField.rightView = [[UIView alloc] init];
        self.subjectTextField.text = self.SenddetailModel.title;
        self.contentText.text = self.SenddetailModel.content;
      self.sendTextField.text   = self.SenddetailModel.sourceFrom;

                 self.title = @"编辑";
    }
    else if (self.type == Retweet) //转发
    {
 self.sendTextField.rightView = [[UIView alloc] init];
//       self.sendTextField.text   = self.SenddetailModel.sendTo;

        self.subjectTextField.text =[NSString stringWithFormat:@"转发 :%@",self.SenddetailModel.title];
        self.SenddetailModel.title =[NSString stringWithFormat:@"转发 :%@",self.SenddetailModel.title];
        self.contentText.text = self.SenddetailModel.content;
                 self.title = @"转发";
    }else{
        self.title = @"发邮件";
    }
}


#pragma mark 添加发送人
-(void)addNameAction:(UIButton*)btn{
    
//    OACityNameViewController * nameVC = [[OACityNameViewController alloc]init];
//    __weak typeof(self) weakSelf = self;
//    nameVC.GetNameStringBlock = ^(NSString * str){
//        weakSelf.sendTextField.text = str;
//    };
//    [self.navigationController pushViewController:nameVC animated:YES];
UIStoryboard * stroyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    OAMainAddressViewController * mainAddressVC = [stroyBoard instantiateViewControllerWithIdentifier:@"mainAddressVCID"];
    mainAddressVC.addressType = NolmalMainAddressType;
                                              mainAddressVC.hidesBottomBarWhenPushed = YES;

    [self.navigationController pushViewController:mainAddressVC animated:YES];

}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
//    if (textField == self.sendTextField) {
//        return NO;
//    }
    return YES;
}

//- (BOOL)textFieldShouldReturn:(UITextField *)textField{
//    [textField resignFirstResponder];
//        [self.view endEditing:YES];
//
//    return YES;
//}


- (void)keybordDown {
      [self.view endEditing:YES];

}

#pragma mark 发送邮件
- (IBAction)sendEmail:(UIBarButtonItem *)sender {
    [self keybordDown];
    
    if ([self.sendTextField.text length] == 0) {
        [self.view makeToast:@"对不起，你的收件人不可以为空"];
        return;
    }
    if ([self.subjectTextField.text length] == 0) {
          [self.view makeToast:@"对不起，你的主题不可以为空"];
        return;
    }
    
//    if ([self.contentText.text length] ==0) {
//          [self.view makeToast:@"对不起，你的内容不可以为空"];
//        return;
//    }
    
    [self uploadEmail];
    
}

-(NSString *)returnString
{
    NSString *string = [[NSString alloc]init];
    string = @"&lt;名称&gt;%@&lt;/名称&gt;\n"
    "&lt;内容&gt;%@&lt;/内容&gt;\n";
    
    NSMutableString *str = [NSMutableString string];
    for (int i = 0; i<self.attachmentArray.count; i++) {
        OAAttachmentsModel * attachModel = self.attachmentArray[i];
        [str appendString: [NSString stringWithFormat:string,attachModel.attachmentsTitle,attachModel.attachmentsURL]];
    }
    
    return str;
}


-(void)uploadEmail{
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * password = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * body = nil;
  if ([_types isEqualToString:@"grcg"]){
  _url = @"exchmail";
  _method = @"senddraftMail";
  
  }else if ([_types isEqualToString:@"kscg"]){
  _url = @"exchksmail";
  _method = @"senddraftMail";
  
  }
 if (self.type == Retweet) {
        
      body =  [NSString stringWithFormat:@"&lt;?xml version=\'1.0\' encoding=\'utf-8\'?&gt;\n"
         "&lt;交换 xmlns=\'exch.jhsx.gov.cn/data\' xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\'&gt;\n"
         "&lt;数据&gt;\n"
         "&lt;数据要素&gt;\n"
         "&lt;unid&gt; %@ &lt;/unid&gt;\n"
         "&lt;Subject&gt; %@ &lt;/Subject&gt;\n"
         "&lt;SendTo&gt; %@ &lt;/SendTo&gt;\n"
         "&lt;body&gt; %@ &lt;/body&gt;\n"
         "&lt;/数据要素&gt;\n"
         "&lt;附件&gt;\n"
         "%@"
         "&lt;/附件&gt;\n"
         "&lt;/数据&gt;\n"
         "&lt;/交换&gt;"
              ,self.uid,self.subjectTextField.text,self.sendTextField.text,self.contentText.text,[self returnString]];
    }else{
        body =  [NSString stringWithFormat:@"&lt;?xml version=\'1.0\' encoding=\'utf-8\'?&gt;\n"
                 "&lt;交换 xmlns=\'exch.jhsx.gov.cn/data\' xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\'&gt;\n"
                 "&lt;数据&gt;\n"
                 "&lt;数据要素&gt;\n"
                 "&lt;Subject&gt; %@ &lt;/Subject&gt;\n"
                 "&lt;SendTo&gt; %@ &lt;/SendTo&gt;\n"
                 "&lt;body&gt; %@ &lt;/body&gt;\n"
                 "&lt;/数据要素&gt;\n"
                 "&lt;/数据&gt;\n"
                 "&lt;/交换&gt;"
                 ,self.subjectTextField.text,self.SenddetailModel.sendfrom,self.contentText.text ];
    }
    
   
    NSArray * array = @[@{@"userId":userId},@{@"pwdId":password},@{@"famxml":body}];
    [HttpTools postWithURL:_url arrays:array method:_method success:^(id JSON) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        
        GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData: [JSON dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
        GDataXMLElement *rootElement = [doc rootElement];
        NSArray *arrData= [rootElement elementsForName:@"info"];
        NSString * message= nil;
        for (GDataXMLElement * subXMLElement in arrData) {
            GDataXMLElement * element = [[subXMLElement elementsForName:@"msg"] objectAtIndex:0];
            message  = [element stringValue];
        }
        if ([message isEqualToString:@"1044"]) {
             [self.view makeToast:@"发送失败"];
        }else if ([message isEqualToString:@"20"]){
             [self.view makeToast:@"发送成功"];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshData" object:nil]; //刷新发件箱，收件箱 数据
//              for (UIViewController * VC in self.navigationController.viewControllers) {
//        if ([VC isKindOfClass:[gerenemailViewController class]]) {
//            [self.navigationController popToViewController:VC animated:YES];
//            break;
//        }
//    }
 [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];

//            [self.navigationController popViewControllerAnimated:YES];
            
        }else{
             [self.view makeToast:@"发送失败"];
        }
     
    } failure:^(NSError *error) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        [self.view makeToast:@"发送失败"];
    }];

}


- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
//文字向上移动
    [UIView animateWithDuration:0.2 animations:^{
    self.view.transform = CGAffineTransformMakeTranslation(0, 0);
    }];
  
    return YES;
}


- (void)textViewDidEndEditing:(UITextView *)textView{
    
    [UIView animateWithDuration:0.2 animations:^{
         self.view.transform = CGAffineTransformIdentity;
    }];
   
    
}
@end
